package com.itheima.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.CheckItemService;
import com.itheima.health.vo.CheckGroupVO;
import io.swagger.annotations.*;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//import com.itheima.health.pojo.User22;

/**
 * @program: health_paret
 * @description:
 * @author: Mr.Wang
 * @create: 2020-11-03 21:45hahahhahahah78910
 **/
@RestController
//ssss
@Api(tags = "菠菜项目管理开发")
public class CheckGroupWeb {
    @Reference
    private CheckItemService checkItemService;
    @Reference
    private CheckGroupService checkGroupService;
//编辑中根据基本信息的id进行回滚检查项目、
    @GetMapping("checkgroup/findCheckItemInfoByGroupId/{id}")
    public Result findCheckItemInfoByGroupId(@PathVariable int id){
        CheckGroupVO checkItemInfoByGroupId = checkGroupService.findCheckItemInfoByGroupId(id);

        return new Result(true,"输入错误",checkItemInfoByGroupId);
    }


    //查询所有检查项目
    @GetMapping("checkgroup/findall")
    public Result findAll() {
        List<CheckItem> list = checkItemService.list();
        return new Result(true, "查询成功", list);
    }

    //前端检查项进行删除数据 进行逻辑删除
    @DeleteMapping("checkgroup/deleteCheckgroupByid/{id}")
    public Result delete(@PathVariable int id) {
        System.out.println("id = " + id);
        Boolean delete = checkGroupService.updateCheckGroupById(id);
        return new Result(delete,"保存成功");
    }

    ////前端发过来的添加用户请求以及进行用户的修改
    @PostMapping("checkgroup/addcheckgroup")
    public Result add(@RequestBody CheckGroupDTO checkGroupDTO) {
        Boolean aBoolean = checkGroupService.saveCheckGroup(checkGroupDTO);
        return new Result(aBoolean, "保存成功");
    }

    //分页进行检查组的初始话
    @ApiOperation(value = "套餐查询", notes = "分页套餐查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前分页页码", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示记录数", required = true, paramType = "form", dataType = "Integer"),
            @ApiImplicitParam(name = "queryString", value = "查询条件", required = false, paramType = "form", dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对")
    })
    @PostMapping("checkgroup/findpage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean) {
        return new Result(true, "正确", checkGroupService.findPage(queryPageBean));
    }
}
